package cn.mothin.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.mothin.entity.SystemUser;
import cn.mothin.frame.core.base.BaseDao;

@Repository("c0304633-221d-476b-ba9d-69190d8eba9d")
public class SystemUserDao extends BaseDao<SystemUser> {
    /**
     * 查询超级用户是否存在
     * 
     * @return
     */
    public boolean querySuperUserExist() {
        String sql = "SELECT COUNT(0) FROM system_user WHERE deleted<>TRUE AND superUser = TRUE";
        return sqlHelper.queryCount(sql) > 0;
    }

    /**
     * 根据给定的帐号查找全部系统用户信息
     * 
     * @param account
     *            登录账号
     * @return
     */
    public List<SystemUser> findSystemUsersByAccount(String account) {
        String sql = "SELECT * FROM system_user WHERE deleted <> TRUE AND account=?";
        return query(sql, account);
    }

    /**
     * 查询该组织下的人员
     * 
     * @param organizationId
     * @return
     */
    public List<String> querySystemUser(String organizationId) {
        String sql = "SELECT id FROM system_user WHERE deleted <> TRUE AND organizationId = ? ";
        return sqlHelper.queryForList(String.class, sql, organizationId);
    }

    public List<SystemUser> findByAccountNotId(String account, String id) {
        String sql = "SELECT * FROM system_user WHERE deleted<>TRUE AND account=? and id <> ? ";
        return query(sql, account, id);
    }

    /**
     * 查询用户原本所属组织机构
     * 
     * @param id
     * @return
     */
    public List<String> queryOrganization(String id) {
        String sql = "SELECT organizationId FROM system_user WHERE deleted <> TRUE AND id = ? ";
        return sqlHelper.queryForList(String.class, sql, id);
    }

    /**
     * 根据组织id查出部门负责人
     * 
     * @param id
     * @return
     */
    public List<String> queryManager(String id) {
        String sql = "SELECT manager FROM organization WHERE deleted <> TRUE AND id = ? ";
        return sqlHelper.queryForList(String.class, sql, id);
    }

    /**
     * 查询用户分管部门信息
     * 
     * @param id
     * @return
     */
    public List<String> queryOrgManger(String id) {
        String sql = "SELECT id FROM organization_manager WHERE managerId = ? ";
        return sqlHelper.queryForList(String.class, sql, id);
    }

}
